package cn.congzhou.crm.query;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Collections;
import java.util.List;

@Getter@Setter@ToString
public class ResultGridData {
    public static final ResultGridData EMPTY_RESULT =
                new ResultGridData(0,0,0, Collections.EMPTY_LIST);

    private Integer currentPage;//当前页码
    private Integer pageSize;//页面大小
    private Integer pages;//总页数
    private Integer prePage;//上一页页码
    private Integer nextPage;//下一页页码
    private Integer total;//总记录数
    private List<?> list;//数据集合

    public ResultGridData (Integer currentPage,Integer pageSize,Integer total,List<?> list){
        this.currentPage=currentPage;
        this.pageSize=pageSize;
        this.total=total;
        this.list=list;
        if(total<=pageSize){
            this.pages=1;
            this.prePage= 1;
            this.nextPage=1;
            return;
        }

        this.pages=total%pageSize==0 ? total/pageSize : total / pageSize +1;
        this.prePage = currentPage-1>=1 ? currentPage - 1 : 1;
        this.nextPage = currentPage+1<=pages ? currentPage + 1 : pages;
    }


}
